package com.tianji.learning.util;


import java.util.Date;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.TimeUnit;

public class DelayedTaskTest {
    public static void main(String[] args) throws InterruptedException {
        DelayQueue<DelayedTask<String>> queue = new DelayQueue<>();
        DelayedTask<String> task1 = new DelayedTask<>("hello", 5, TimeUnit.SECONDS);
        DelayedTask<String> task2 = new DelayedTask<>("world", 3, TimeUnit.SECONDS);
        DelayedTask<String> task3 = new DelayedTask<>("demo", 1, TimeUnit.SECONDS);
        System.out.println(new Date() +":put task" );
        queue.put(task1);
        queue.put(task2);
        queue.put(task3);
        while(true){
            DelayedTask<String> task = queue.take();
            System.out.println(new Date() +":" + task.getData());
        }
    }
}